package cc.linker.steplink.crm.controller.form;

import cc.linker.steplink.crm.commons.form.FormRequest;
import cc.linker.steplink.crm.commons.model.FormLoginDto;
import cc.linker.steplink.crm.merchanth5.commons.FormFilter;
import cc.linker.steplink.crm.response.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @Author: CKQ
 * @DateTime: 2020/10/28 9:37
 * @Description: TODO
 */
@Slf4j
@Controller
public class ExportFormController {
    @Autowired
    private FormRequest formRequest;
    @Autowired
    private FormFilter formFilter;

    /**
    * @Description：导出重定向
    * @DateTime：2020/10/28 9:39
    * @Params：
    * @Return：
    */
    @RequestMapping("/pc/form/export")
    public String exportFormData(HttpServletRequest request) throws GlobalException, UnsupportedEncodingException {
        FormLoginDto formLoginDto = formFilter.getFormLoginDto(request, false);
        String url = this.formRequest.exportData(request, formLoginDto);
        return "redirect:" + url;
    }

    @RequestMapping("/pc/form/down/files")
    public String downFormFiles(HttpServletRequest request) throws GlobalException, UnsupportedEncodingException {
        FormLoginDto formLoginDto = formFilter.getFormLoginDto(request, false);
        String url = this.formRequest.exportData(request, formLoginDto);
        return "redirect:" + url;
    }
}
